package com.senlingspace.payment.config;

import com.senlingspace.common.exception.payment.DouyinException;
import com.senlingspace.payment.config.properties.DouyinProperties;
import com.senlingspace.payment.douyin.DouyinHttpClient;
import com.senlingspace.payment.utils.DouyinSignUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 抖音初始化配置
 *
 * @author lebronjames
 * @date 2024/07/22
 */
@Slf4j
@Configuration
public class DouyinConfig {

    @Autowired
    private DouyinProperties douyinProperties;

    @Bean
    public void initializeDouyin() throws DouyinException {
        DouyinHttpClient.init(douyinProperties.getServerUrl(), douyinProperties.getClientKey(), douyinProperties.getClientSecret(),
                null, null, null);

        // 初始化 DouyinSignUtil 的 secret
        DouyinSignUtil.setSecret(douyinProperties.getClientSecret());
    }

}
